<?php
/** 
 * $Source: /cvsroot/pn-commerce/pn-commerce/pntemplates/plugins/function.pncAddItem.php,v $
 * $Author: landseer $
 * $Revision: 1.8 $
 * $Date: 2004/06/27 12:18:54 $
 *
 * Type: Function
 *
 * returns the complete <form></form> code for adding an item to the cart
 *@param params['ItemID'] int the id of the item
 *@param params['Long'] boolean true creates the long version of the, default is false 
 *@param params['ShowCart'] boolean true shows the cart after adding something, default is the
 *@param params['ReturnURL'] string an url to return to after adding the item to the cart.
 *                           If both ShowCart and ReturnURL are set, ReturnURL is used
 *@return string complete <form></form> code for adding a specific item to the cart
 */
function smarty_function_pncAddItem($params, &$smarty)
{
    extract($params);

    if( !$ItemID )
    {
        $smarty->trigger_error( "pncAddItem: missing parameter ItemID" );
    }
    if( !$Long )
    {
        $Long = false;
    }
    if( !$ShowCart )
    {
        $ShowCart = pnModGetVar( 'pncommerce', 'JumpToCartviewAfterAdd' );
    }
    
    if( !pnModAPILoad( 'pncommerce', 'user' ) )
    {
        return false;
    }
    $url = pnModAPIFunc( 'pncommerce', 'user', 'pncModURL',
                         array( 'Module'   => 'pncommerce',
                                'Section'  => 'user',
                                'Function' => 'itemedit' ) );
    $temp  = "<form action='$url' method='post'\n>";
    $temp .= "<input type='hidden' name='authid' value='". pnSecGenAuthKey( 'pncommerce' )."'>";
    if( $Long == false )
    {
        $temp .= "<input type='hidden' name='ItemID' value='$ItemID'>\n";
        $temp .= "<input type='hidden' name='Mode' value='add'>\n";
        $temp .= "<input class='pn-button' type='submit' value='"._PNC_ADD."'>\n";
        $temp .= "<input type='text' name='ItemQuantity' value='1' size='3'>\n";
    }
    elseif( $Long == true )
    {
        $temp .= "<font class='pn-normal'>"._PNC_ADD."</font>\n";
        $temp .= "<input type='text' name='ItemQuantity' value='1' size='2'>"._PNC_THISTOMYCART."</font>\n";
        $temp .= "<input type='hidden' name='ItemID' value='$ItemID'>\n";
        $temp .= "<input type='hidden' name='Mode' value='add'>\n";
        $temp .= "<input class='pn-button' TYPE='submit' VALUE='"._PNC_ADDTOMYCART."'>\n";
    }
    if( isset($ReturnURL) )
    {
            $temp .= "<input type='hidden' name='returnurl' value='$ReturnURL' >\n";
    }
    else
    { 
        if( $ShowCart == 'on' )
        {
            $temp .= "<input type='hidden' name='cartview' value='on' >\n";
        }
    }
    $temp .= "</form>";
    return $temp;

}
?>
